Migrate web core to signals#795
Conversation
There was a problem hiding this comment.
Code Review
This pull request migrates the reactive programming paradigm from RxJS Observables to Preact Signals across the web_core renderer. Key changes include updating package.json dependencies, refactoring DataContext and DataModel classes to use Signals for reactive value resolution and subscriptions, and adapting function implementations and tests accordingly. Specifically, rxjs imports are replaced with @preact/signals-core, FunctionImplementation types are updated, and the internal subscription and notification mechanisms in DataModel are re-engineered to leverage Signals, including shallow cloning for object/array updates. Review comments highlight a resource leak in a test metronome function due to the lack of a cleanup mechanism for setInterval after the migration from Observables, the removal of essential JSDoc comments from the DataContext class that need to be restored, and a request to replace verbose internal comments in DataModel's updateSignal with a concise explanation for shallow copying. An outdated test description also needs to be updated to reflect the change from observables to signals.
This PR migrates the core reactive reactivity system in
web_corefrom RxJS to Preact Signals.Motivation
The migration to Preact Signals significantly simplifies the data-binding layer and aligns with a more modern, synchronous state management paradigm. RxJS
Observablestreams, while powerful, introduce overhead when handling simple state properties and make synchronous resolution complex (e.g., needing to emit an initial value synchronously upon subscription). Signals inherently hold a current value and provide granular reactivity with less boilerplate.Key Architectural Changes
DataContextReactivity ModelObservable,combineLatest,switchMap, etc.).resolveSignal<V>(), which converts A2UIDynamicValueobjects (literals, paths, and function calls) into a reactive PreactSignal<V>.subscribeDynamicValuenow creates a Preacteffectthat watches the underlyingSignaland emits changes to the subscriber.DataModel Updates
DataModelwas refactored to manage a map of paths toSignalinstances rather than relying on custom RxJS subjects.Function Execution & Resource Management (
AbortSignal)setIntervaltimers in themetronomefunction), introduced the Cancellation Token Pattern using standard webAbortSignalAPIs.abortSignal?: AbortSignalparameter.DataContextnow creates anAbortControllerfor each reactive function execution. It aborts the controller when the function arguments change (triggering a re-evaluation) or when the component utilizing the function is disposed.Basic Functions & Catalog
BASIC_FUNCTIONS(likeformatString) to consume and returnSignals instead ofObservables.formatStringnow usescomputed()to combine dynamic parts.Test Migration
valueresolution, replacing RxJS subscription testing patterns.